#include <iostream>
#include <vector>
#include <set>
#include <queue>

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define VAR(v, n) __typeof(n) v = (n)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define PB push_back
#define ST first
#define ND second

using namespace std;

struct React {
	set<int> subs;
	vector<int> prods;
};

struct Sub {
	char is;
	set<int> re;
};

int main() {
	int n,k,r,i,a,s,p,j,sj,pj,ij;
	
	React *reacts;
	Sub *subs;
	queue<int> ready;
		
	cin >> n >> k >> r;
	
	subs = new Sub[n+1]; REP(i,n+1) subs[i].is = 0;
	reacts = new React[r+1];

	//owns substraction
	REP(i,k) {
		cin >> a;
		ready.push(a);
	}
	
	//
	REP(i,r) {
		cin >> s;
		REP(j,s) {
			cin >> sj;
			reacts[j].subs.insert(sj);
			subs[sj].re.insert(j);
		}
		cin >> p;
		REP(j,p) {
			cin >> pj;
			reacts[j].prods.push_back(pj);
		}
	}

	while(!ready.empty()) {
		i = ready.front();
		ready.pop();
		FOREACH(re,subs[i].re) {
			if(reacts[*re].subs.size() > 0) {
				reacts[*re].subs.erase(i);
				if(reacts[*re].subs.empty()) {
					FOREACH(p,reacts[*re].prods) {
						if(subs[*p].is == 0) {
							ready.push(*p);
						}
					}
				}
			}
		}
		subs[i].is = 1;
		cout << "DDD\n";
	}
/*
	while(was == true) {
		was = false;
		cout << "CCC\n";
		FOREACH(react,cant) {
			all = true;
			FOREACH(i,(*react)->sub) {
				all = all && (poss[*i]);
			}
//			cout << "BBB\n";
			if(all == 1) {
				FOREACH(i,(*react)->prod) {
					poss[*i] = true;
					got.insert(*i);
				}
				was = true;
				cout << "AAA\n";
				rcan.insert(*react);
				cant.erase(*react);
			}
		}
	}
	
	FOREACH(i,owns) got.erase(*i);
*/
//	cout << got.size() << endl;
/*	
	cout << "poss:\n";
	REP(i,n) cout << "poss["<<i<<"]="<<poss[i]<<endl;
	cout << endl;
	
	cout << "reacts:\n";
	REP(i,r) {
		cout << "s("; 
		FOREACH(j,reacts[i].sub) cout << *j << " ";
		cout << ") p("; 
		FOREACH(j,reacts[i].prod) cout << *j << " ";
		cout << ")\n";
	}
	
	cout << "rcan:\n";
	FOREACH(i,rcan) {
		cout << "s("; 
		FOREACH(j,(*i)->sub) cout << *j << " ";
		cout << ") p("; 
		FOREACH(j,(*i)->prod) cout << *j << " ";
		cout << ")\n";
	}

	cout << "cant:\n";
	FOREACH(i,cant) {
		cout << "s("; 
		FOREACH(j,(*i)->sub) cout << *j << " ";
		cout << ") p("; 
		FOREACH(j,(*i)->prod) cout << *j << " ";
		cout << ")\n";
	}
*/
	
	return 0;
}
